package club.caihappy.test;

import club.caihappy.config.MainConfigOfAutowired;
import club.caihappy.config.MainConfigOfProfile;
import club.caihappy.pojo.Boss;
import club.caihappy.pojo.Car;
import club.caihappy.pojo.Color;
import club.caihappy.pojo.Yellow;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.Environment;
//import org.springframework.core.env.Environment;

import javax.sql.DataSource;

/**
 * Created by DELL on 2021/10/9
 **/
public class IOCTest_ProFile {

    AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();


    //声明调用环境方法二:
    @Test
    public void test1() {
        applicationContext.getEnvironment().setActiveProfiles("test", "dev");
        applicationContext.register(MainConfigOfProfile.class);
        applicationContext.refresh();
        String[] beanNamesForType = applicationContext.getBeanNamesForType(DataSource.class);
        for (String s : beanNamesForType) {
            System.out.println(s);
        }
        Yellow bean = applicationContext.getBean(Yellow.class);
        System.out.println(bean);
    }


//    ApplicationContext applicationContext = new AnnotationConfigApplicationContext(MainConfigOfProfile.class);
//    //声明调用环境方法一:使用命令行动态参数:在虚拟机参数位置加载: -Dspring.profiles.active=test
//    @Test
//    public void test1(){
//        String[] beanNamesForType = applicationContext.getBeanNamesForType(DataSource.class);
//        for (String s : beanNamesForType) {
//            System.out.println(s);
//        }
//    }

}
